<template>
<view class="shop">
   <view class="content">
      <view v-for="(item, index) in shopList" :key="index" class="shopimg" @tap="toShop" :data-gid="index">
         <image :src="item.thumb_img" class="img"></image>
         <view class="text" style="word-break: break-all;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">{{item.goods_name}}</view>
         <view class="money">￥{{item.price}}</view>
      </view>
   </view>
   <view v-if="noshop" class="noshop">没有更多了...</view>
</view>
</template>

<script>
// hotmall/packageB/shopList/shopList.js
import api from "../../../api";
var app = getApp();

export default {
  data() {
    return {
      shopList: [],
      type: '',
      page: 1,
      noshop: false
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      type: options.type
    });
    this.getList();
  },
  // //店铺路由
  // toShop(e) {
  //    console.log(e)
  //    var l = e.currentTarget.dataset.index;
  //    console.log(l)
  //    var id = this.data.shopID[l]
  //    var name = this.data.shopName[l]
  //    var logo = this.data.shopLogo[l]
  //    wx.navigateTo({
  //       url: '../../packageA/goodShop/goodShop?id=' + id + '&name=' + name + '&logo=' + logo,
  //    })
  // },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // if (this.data.status != 0) {
    this.setData({
      page: this.page + 1
    });
    this.getList(); // }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getList: function () {
      app.globalData.request({
        url: api.default.goods_goods_list,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        data: {
          type: this.type,
          goods_type: 1,
          page: this.page
        },
        success: res => {
          console.log(res);

          if (this.page == 1) {
            this.setData({
              shopList: res.list
            });
          } else {
            if (res.list.length == 0) {
              this.setData({
                noshop: true
              });
            } else {
              var shop = this.shopList;

              for (let i = 0; i < res.list.length; i++) {
                shop.push(shop[i]);
              }

              this.setData({
                shopList: shop
              });
              console.log(this.shopList);
            }
          }
        }
      });
    },
    //跳转商品详情页
    toShop: function (event) {
      console.log(event);
      console.log(event.currentTarget.dataset.gid);
      let index = event.currentTarget.dataset.gid;
      wx.navigateTo({
        url: '../../packageA/rushdetails/rushdetails?goods_id=' + this.shopList[index].goods_id + '&img=' + this.shopList[index].thumb_img
      });
    }
  }
};
</script>
<style>
@import "./recgoods.css";
</style>